package com.base.monitor.admin.controller.biz.cfg;

import com.base.monitor.framework.annotation.RefuseResponseResult;
import com.base.monitor.framework.annotation.ResponseResult;
import com.base.monitor.framework.result.PageResult;
import com.base.monitor.model.model.biz.cfg.crierita.GatewayCriteria;
import com.base.monitor.model.model.biz.cfg.dto.GatewayGenerateCommandDto;
import com.base.monitor.model.model.biz.cfg.entity.Gateway;
import com.base.monitor.module.biz.service.cfg.GatewayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/cfg/gateway")
@ResponseResult
public class GatewayController {

    @Autowired
    private GatewayService gatewayService;

    /**
     * 分页条件查询
     * @param criteria 查询条件
     * @return
     */
    @GetMapping
    @RefuseResponseResult
    public PageResult<Gateway> page(GatewayCriteria criteria) {
        return gatewayService.page(criteria);
    }

    /**
     * 下发获取版本的命令
     */
    @GetMapping("/version")
    public void writeVersionCommand() {
        gatewayService.sendVersionCommand();
    }

    /**
     * 生成下发命令
     * @param gatewayGenerateCommandDto 生成命令需要的实体信息
     * @return
     */
    @PostMapping("/generate")
    public Map<String, String> generate(@RequestBody GatewayGenerateCommandDto gatewayGenerateCommandDto) {
        return gatewayService.generate(gatewayGenerateCommandDto);
    }

    /**
     * 下发指令
     * @param gatewayGenerateCommandDto 下发指令需要的实体信息
     */
    @PostMapping("/writeCollectCommand")
    public void writeCollectCommand(@RequestBody GatewayGenerateCommandDto gatewayGenerateCommandDto) {
        gatewayService.writeCollectCommand(gatewayGenerateCommandDto);
    }

    /**
     * 查看下发结果
     * @param gatewayGenerateCommandDto 查看结果需要的实体信息
     */
    @PostMapping("/getCollectResult")
    public void getCollectResult(@RequestBody GatewayGenerateCommandDto gatewayGenerateCommandDto) {
        gatewayService.checkCollectResult(gatewayGenerateCommandDto);
    }
//
//    /**
//     * 生成下发命令
//     * @param id 网关id
//     * @return
//     */
//    @GetMapping("/generate")
//    public Map<String, String> generate(Long id) {
//        return gatewayService.generate(id);
//    }
//
//    /**
//     * 刷新数据
//     */
//    @GetMapping("/refresh")
//    public void refresh() {
//        gatewayService.refresh();
//    }

}
